---
title: Freeze
---

<Callout type="warning">
  Freezing uses the top-left corner of the current selection as the freeze point. Therefore, if the current selection is cell A1, freezing will not be effective.
</Callout>

[`IWorksheetData.freeze`](/guides/sheets/model/workbook-data) can be used to configure the freeze state of a worksheet. Its interface definition is as follows:

```typescript
interface IFreeze {
  /**
   * The number of frozen columns
   */
  xSplit: number
  /**
   * The number of frozen rows
   */
  ySplit: number
  /**
   * The starting row that can be scrolled (the starting row of the main view area)
   */
  startRow: number
  /**
   * The starting column that can be scrolled (the starting column of the main view area)
   */
  startColumn: number
}
```

For example, if I want to freeze column B and row 2, I can configure it like this:

```json
{
  "xSplit": 1, // Freeze 1 column, which is column B
  "ySplit": 1, // Freeze 1 row, which is row 2
  "startRow": 2, // The starting row that can be scrolled is row 3
  "startColumn": 2 // The starting column that can be scrolled is column C
}
```

If you want to implement custom freeze functionality, such as freezing the first row and first column, you can refer to:

- [Custom Menu](/guides/recipes/tutorials/custom-plugin)
- [SetFrozenCommand](https://github.com/dream-num/univer/blob/dev/packages/sheets/src/commands/commands/set-frozen.command.ts#L32)

## Facade API

The `FWorksheet` class provides several methods to manage the freeze state of rows and columns in a worksheet. These methods allow you to set, get, and cancel frozen panes.

### Set Freeze

```typescript
const worksheet = univerAPI.getActiveWorkbook().getActiveSheet()
worksheet.setFreeze({
  xSplit: 1, // Freeze 1 column, which is column B
  ySplit: 1, // Freeze 1 row, which is row 2
  startRow: 2, // The starting row that can be scrolled is row 3
  startColumn: 2, // The starting column that can be scrolled is column C
})
console.log('The current freeze state:', worksheet.getFreeze())
```

### Set Frozen Columns

```typescript
const worksheet = univerAPI.getActiveWorkbook().getActiveSheet()

// Set freeze for columns A-B
worksheet.setFrozenColumns(2)
```

### Set Frozen Rows

```typescript
const worksheet = univerAPI.getActiveWorkbook().getActiveSheet()

// Set freeze for the first 3 rows
worksheet.setFrozenRows(3)
```

### Get Freeze State

```typescript
const worksheet = univerAPI.getActiveWorkbook().getActiveSheet()

const freezeState = worksheet.getFreeze()
```

### Get Frozen Columns

```typescript
const worksheet = univerAPI.getActiveWorkbook().getActiveSheet()

const frozenColumns = worksheet.getFrozenColumns()
```

### Get Frozen Rows

```typescript
const worksheet = univerAPI.getActiveWorkbook().getActiveSheet()

const frozenRows = worksheet.getFrozenRows()
```

### Cancel Freeze

```typescript
const worksheet = univerAPI.getActiveWorkbook().getActiveSheet()

// Cancel all freezes
worksheet.cancelFreeze()
```
